home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows4 / pcproj.zip / PROJ.ACT < prev    next >
Text File  |  1990-01-29  |  7KB  |  258 lines

  1. /* proj.act       --miscelaneous methods, initializations
  2. */
  3.  
  4. /* globals for application colors */
  5. Actor[#CritColor]:=RED;
  6. Actor[#SlackColor]:=BLUE;
  7. !!
  8.  
  9. /* globals for conditional compilation during debugging etc */
  10.  
  11. Actor[#Debug] := false;     /* debugging enable/disable */
  12. Actor[#Trace] := false;     /* trace recalc calls */      
  13. Actor[#CurPos] := 0;        /* text dump of network uses this */ 
  14. !!
  15.  
  16. /* methods for system classes */
  17.  
  18. now(Window)!!
  19.  
  20. /* Set the current cursor position in client coords.
  21.    This is useful when implementing a keyboard interface. */
  22. Def  setCursorPos(self, pos | scrnPos)
  23.   scrnPos := clientToScreen(self, pos);
  24.   Call SetCursorPos(scrnPos.x, scrnPos.y);
  25. }!!
  26.  
  27. /* Return a point of the current cursor position in client coords.
  28.    This is useful when implementing a keyboard interface. */
  29. Def  getCursorPos(self | struct, scrnPos, lpr)
  30.   struct := new(Struct,4);          /* to store the point */
  31.   lpr := lP(struct);                /* long pointer */
  32.   Call GetCursorPos(lpr);           /* device coords */
  33.   scrnPos := pointAt(lpr);          /* get the data */
  34.   freeHandle(struct);               /* free up memory */
  35.   ^screenToClient(self, scrnPos);   /* screen coords */
  36. }!!
  37.  
  38. /* Return a point giving the text width and height
  39.    in the given display context. 
  40.    e.g. for system font the return value might be 
  41.    8@15 for 8 pixels wide, 15 high, depending on the
  42.    Windows drivers. */
  43. Def  textSize(self, hDC | tm1, tm2)
  44.   tm1 := new(Struct, 31);            /* to hold the info */
  45.   Call GetTextMetrics(hDC, lP(tm1)); /* call Windows fn */
  46.   tm2 := getData(tm1);               /* get the data back */
  47.   freeHandle(tm1);                   /* free up memory */
  48.   ^point(low(tm2[10]), low(tm2[0])); /* width@height */
  49. }!!
  50.  
  51. now(Dialog);!!
  52.  
  53. /* Run the dialog with the appropriate resource
  54.    and parent.  Display a warning if it fails. */
  55. Def  checkRunModal(self, res, parent | retValue)
  56. {
  57.   retValue := runModal(self, res, parent);
  58.   if retValue == NOMEM
  59.     beep();
  60.     errorBox(loadString(PW_WARNING),
  61.              loadString(PW_ERRMEM1) + CR_LF +
  62.              loadString(PW_ERRMEM2));
  63.   endif;
  64.   ^retValue;
  65. }!!
  66.  
  67. now(String);!!
  68.  
  69. /* Return the string in a field of fieldSize.
  70.    Truncate or pad with blanks as necessary.
  71. */
  72. Def  field(self, fieldSize | size)
  73. {
  74.   if fieldSize < size := size(self)
  75.     ^subString(self, 0, fieldSize)            /* truncate */
  76.   else
  77.     ^self + stringOf(' ', fieldSize - size);  /* pad */
  78.   endif;
  79. }!!
  80.  
  81. /* Convert to decimal.  Safe if length = 0. */
  82. Def  asDec(self)
  83. {
  84.   if size(self) = 0
  85.     ^ 0;
  86.   else
  87.     ^asInt(self,10);
  88.   endif;
  89. }!!
  90.  
  91. /* Show a yesNoBox with self as the caption, str as message.  
  92.    Return value of 6 = IDYES, 7 = IDNO. */
  93. Def yesNoBox(self, str)
  94. {  ^new(ErrorBox, ThePort, str, self, 4);
  95. }!!
  96.  
  97. /* Convert a string into a Date object.
  98.    Use the international string format.  
  99.    Return nil if not a valid date. */
  100. Def asIntlDate(self | sep, format, ints, posn, pos1, pos2, mm, dd, yy)
  101. { sep := getProfileString(System, "intl", "sDate");
  102.   if sep = "" then sep := "/"; endif;
  103.   format := getProfileString(System, "intl", "iDate");
  104.   select
  105.     case format = "2"
  106.       posn := #(2 0 1); /* YYMMDD */
  107.     endCase
  108.     case format = "1"
  109.       posn := #(1 0 2); /* DDMMYY */
  110.     endCase
  111.     default       
  112.       posn := #(0 1 2); /* MMDDYY */
  113.   endSelect;
  114.   ints := new(Array, 3);
  115.   pos1 := find(self, sep, 0);
  116.   if not(pos1) ^nil; endif;
  117.   ints[0] := asDec(subString(self, 0, pos1));  
  118.   pos2 := find(self, sep, pos1+1);
  119.   if not(pos2) ^nil; endif;
  120.   ints[1] := asDec(subString(self, pos1+1, pos2));
  121.   ints[2] := asDec(subString(self, pos2+1, size(self)));
  122.   mm := ints[posn[0]];  dd := ints[posn[1]];  yy := ints[posn[2]];
  123.   if not(mm) cor mm > 12 cor mm < 1 ^nil; endif;
  124.   if not(dd) cor dd > 31 cor dd < 1 ^nil; endif;
  125.   if not(yy) cor yy < 0 ^nil; endif;
  126.   if yy < 100 yy := yy + 1900; endif;
  127.   ^date(mm, dd, yy);
  128. }!!
  129.  
  130. /* Report an error if the date string is invalid,
  131.    otherwise return the Date object.  Ignore empty strings.
  132.    Report the error according to international date format. */
  133. Def  checkDate(self | retValue, iDate, format)
  134.   if self <> ""
  135.   cand not(retValue := asIntlDate(self))
  136.     beep();
  137.     iDate := getProfileString(System, "intl", "iDate");
  138.     select
  139.       case iDate = "2"
  140.         format := loadString(PW_YYMMDD);
  141.       endCase
  142.       case iDate = "1"
  143.         format := loadString(PW_DDMMYY);
  144.       endCase
  145.       default                               /* "0" or unspecified */
  146.         format := loadString(PW_MMDDYY);
  147.     endSelect;
  148.     errorBox(loadString(PW_ERRDATE1),
  149.              asString(self) + loadString(PW_ERRDATE2) + format +
  150.              loadString(PW_ERRDATE3));
  151.   endif;
  152.   ^retValue;
  153. }!!
  154.  
  155.  
  156. now(Date)!!
  157.  
  158. /* Modify the asString method to use intl format. */
  159. Def asString(self)
  160. {
  161.   ^asIntlString(self);
  162. }!!
  163.  
  164. /* Convert a date to a string.  NilClass:checkString
  165.    returns an empty string. */
  166. Def  checkString(self)
  167.   ^asString(self);
  168. }!!
  169.  
  170.  
  171. /* Return date in international string format. 
  172.    Abbreviate the year.  */
  173. Def asIntlString(self | sep, form, da, yr)
  174.   sep := getProfileString(System, "intl", "sDate");
  175.   if sep = "" sep := "/"; endif;
  176.   form := getProfileString(System, "intl", "iDate");
  177.   da := asDateArray(self); 
  178.   if da[2] > 1900
  179.     yr := subString(asString(da[2]), 2, 4);
  180.   else
  181.     yr := asString(da[2]);
  182.   endif;
  183.   select
  184.     case form = "2" /* YYMMDD */
  185.      ^yr+sep+asString(da[1])+sep+asString(da[0]);
  186.     endCase
  187.     case form = "1" /* DDMMYY */
  188.      ^asString(da[1])+sep+asString(da[0])+sep+yr;
  189.     endCase
  190.     default         /* MMDDYY */
  191.      ^asString(da[0])+sep+asString(da[1])+sep+yr;
  192.     endSelect;
  193. }!!
  194.  
  195.  
  196. now(Int)!!
  197.  
  198. /* Create a date object with a starting value. */
  199. Def date(self, dd, yy)
  200. {
  201.   ^date(new(Date), self, dd, yy);
  202. }!!
  203.  
  204.  
  205. now(NilObject)!!
  206.  
  207. /* Return an empty string.  For compatibility
  208.    with the Date class so you can checkString(nil)
  209.    or checkString(aDate) and get a string. */
  210. Def  checkString(self)
  211.   ^"";
  212. }!!
  213.  
  214.  
  215. now(Collection)!!
  216.  
  217. /* Returns true (the position) if the elem is in the collection.
  218.    Uses a sequential search.  Descendent classes redefine this
  219.    using more efficient means where possible. */
  220. Def  in(self, elem)
  221. {
  222.   do(size(self),
  223.     {using(i) 
  224.      if self[i] = elem ^i; endif;   /* found */
  225.   });
  226.   ^false;    /* not found */
  227. }!!
  228.  
  229.  
  230. now(Dictionary)!!
  231.  
  232. /* Returns the value (true) if the key is in the Dictionary. */
  233. Def  in(self, key | assoc)
  234. {
  235.   assoc := assocAt(self, key);
  236.   if assoc
  237.     ^assoc.value;
  238.   else
  239.     ^false;
  240.   endif;
  241. }!!
  242.  
  243. now(Object)!!
  244. /* This method overrides the default case of objects not being
  245.    storable so that Project, Milestone, Task etc are all storable.
  246. */
  247. Def notStorable(self)
  248. {
  249.   ^nil;
  250. }!!
  251.